<<<<<<< .mine
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ProgramPSP0
{
    class ReadNumbers
    {

        static string[] zeroToNine = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
        static string[] tenToNineteen = { "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
        static string[] twentyToNinety = { "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" };
        static string[] suffixNumber = { "hundreddd", "thousand", "million", "billon" };

        public static void ConvertNumToAlphabet()
        {
            string numStr;
            List<string> listNum = new List<string>();

            Console.Write("Number : ");
            StreamReader sr = new StreamReader(@"C:\data.txt");
            while ((numStr = sr.ReadLine()) != null)
            {
                Console.Write(numStr + "  ");
                listNum.Add(numStr);
            }

            int length = listNum.Count();
            for (int i = 0; i < length; i++)
            {
                numStr = listNum.ElementAt(i);
                Console.WriteLine("\n");
                if (numStr.Length == 1)
                    Console.WriteLine(ConvertOneNumber(numStr));

                if (numStr.Length == 2)
                    Console.WriteLine(ConvertTwoNumbers(numStr));

                if (numStr.Length == 3)
                    Console.WriteLine(ConvertThreeNumbers(numStr));

                if (numStr.Length == 4)
                    Console.WriteLine(ConvertFourNumbers(numStr));

                if (numStr.Length == 5)
                    Console.WriteLine(ConvertFiveNumbers(numStr));

                if (numStr.Length == 6)
                    Console.WriteLine(ConvertSixNumbers(numStr));
                if (numStr.Length == 7)
                    Console.WriteLine(ConvertSevenNumbers(numStr));

            }
        }

        //หลักหน่วย 1 หลัก 
        public static string ConvertOneNumber(string numStr)
        {
            int num = Convert.ToInt32(numStr);
            return zeroToNine[num];
        }

        //หลักสิบ 2 หลัก 
        public static string ConvertTwoNumbers(string numStr)
        {
            int n = numStr.Length;

            for(int j = 0; j < n; j++)
            {
                int num = Convert.ToInt32(numStr[j]) - 48;

                if (num == 0)
                {
                    int numNext = Convert.ToInt32(numStr[j + 1]) - 48;
                    if (numNext == 0)
                    {
                        return "";
                    }
                    else
                    {
                        return zeroToNine[numNext];
                    }
                }

                if (num == 1)
                {
                    int numNext = Convert.ToInt32(numStr[j + 1]) - 48;
                    return tenToNineteen[numNext];
                }
                else
                {
                    if (numStr[j + 1] == '0')
                    {
                        return twentyToNinety[num - 2];
                    }
                    else
                    {
                        int numNext = Convert.ToInt32(numStr[j + 1]) - 48;
                        return twentyToNinety[num - 2] + " " + zeroToNine[numNext];
                    }
                }
            }

            return "";

        }

        //หลักร้อย 3 หลัก 
        public static string ConvertThreeNumbers(string numStr)
        {
            int n = numStr.Length;
            int num = Convert.ToInt32(numStr[0]) - 48;
            string twoNum = numStr.Substring(1,2);

            if (num == 0)
            {
                if (ConvertTwoNumbers(twoNum) == "")
                    return "";
                else
                    return ConvertTwoNumbers(twoNum);
            }
            else
            {
                if(ConvertTwoNumbers(twoNum) == "")
                    return zeroToNine[num] + " " + suffixNumber[0];
                else
                    return zeroToNine[num] + " " + suffixNumber[0] + " and " + ConvertTwoNumbers(twoNum);
            }

        }

        //หลักพัน 4 หลัก 
        public static string ConvertFourNumbers(string numStr)
        {
            int n = numStr.Length;
            int num = Convert.ToInt32(numStr[0]) - 48;
            string threeNum = numStr.Substring(1, 3);

            if (num == 0)
            {
                if (ConvertThreeNumbers(threeNum) == "")
                    return "";
                else
                    return ConvertThreeNumbers(threeNum);
            }
            else
            {
                if (ConvertThreeNumbers(threeNum) == "")
                    return zeroToNine[num] + " " + suffixNumber[1];
                else
                {
                    return zeroToNine[num] + " " + suffixNumber[1] + " and " + ConvertThreeNumbers(threeNum);
                }
            }
        }

        //หลักหมื่น 5 หลัก
        public static string ConvertFiveNumbers(string numStr)
        {
            int n = numStr.Length;
            string twoFirstNum = numStr.Substring(0,2);
            string threeLastNum = numStr.Substring(2,3);

            if(ConvertTwoNumbers(twoFirstNum) == "")
                 return ConvertTwoNumbers(twoFirstNum) + ConvertThreeNumbers(threeLastNum);
            else
                return ConvertTwoNumbers(twoFirstNum) + " " + suffixNumber[1] + " and " + ConvertThreeNumbers(threeLastNum);
        }

        //หลักแสน 6 หลัก
        public static string ConvertSixNumbers(string numStr)
        {
            int n = numStr.Length;
            string threeFirstNum = numStr.Substring(0, 3);
            string threeLastNum = numStr.Substring(3, 3);

            if (ConvertThreeNumbers(threeFirstNum) == "")
                return ConvertThreeNumbers(threeLastNum);
            else
            {
                if (ConvertThreeNumbers(threeLastNum) == "")
                    return ConvertThreeNumbers(threeFirstNum) + " " + suffixNumber[1];
                else
                    return ConvertThreeNumbers(threeFirstNum) + " " + suffixNumber[1] + " and " + ConvertThreeNumbers(threeLastNum);
            }
        }

        //หลักล้าน 7 หลัก
        public static string ConvertSevenNumbers(string numStr)
        {
            int n = numStr.Length;
            string firstNum = numStr[0].ToString();
            string threeMiddletNum = numStr.Substring(1, 3);
            string threeLastNum = numStr.Substring(4, 3);
            if (firstNum == "0")
            {
                if (ConvertThreeNumbers(threeMiddletNum) == "")
                    return ConvertThreeNumbers(threeLastNum);
                else
                    return ConvertThreeNumbers(threeMiddletNum) + " " + suffixNumber[1] + " and " + ConvertThreeNumbers(threeLastNum);
            }
            else
            {
                if(ConvertThreeNumbers(threeMiddletNum) == "")
                    return ConvertOneNumber(firstNum) + " " + suffixNumber[2] + " and " + ConvertThreeNumbers(threeLastNum);
                else
                   return ConvertOneNumber(firstNum) + " " + suffixNumber[2] + " and " + ConvertThreeNumbers(threeMiddletNum) + " " + suffixNumber[1] + " and " + ConvertThreeNumbers(threeLastNum);
            }
        }
    }
}
=======
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ProgramPSP0
{
    class ReadNumbers
    {

        static string[] zeroToNine = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
        static string[] tenToNineteen = { "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
        static string[] twentyToNinety = { "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" };
        static string[] suffixNumber = { "hundred", "thousand", "million", "billon" };

        public static void ConvertNumToAlphabet()
        {
            string numStr;
            List<string> listNum = new List<string>();

            Console.Write("Number : ");
            StreamReader sr = new StreamReader(@"C:\data.txt");
            while ((numStr = sr.ReadLine()) != null)
            {
                Console.Write(numStr + "  ");
                listNum.Add(numStr);
            }

            int length = listNum.Count();
            for (int i = 0; i < length; i++)
            {
                numStr = listNum.ElementAt(i);
                Console.WriteLine("\n");
                if (numStr.Length == 1)
                    Console.WriteLine(ConvertOneNumber(numStr));

                if (numStr.Length == 2)
                    Console.WriteLine(ConvertTwoNumbers(numStr));

                if (numStr.Length == 3)
                    Console.WriteLine(ConvertThreeNumbers(numStr));

                if (numStr.Length == 4)
                    Console.WriteLine(ConvertFourNumbers(numStr));

                if (numStr.Length == 5)
                    Console.WriteLine(ConvertFiveNumbers(numStr));

                if (numStr.Length == 6)
                    Console.WriteLine(ConvertSixNumbers(numStr));
                if (numStr.Length == 7)
                    Console.WriteLine(ConvertSevenNumbers(numStr));

            }
        }

        //หลักหน่วย 1 หลัก 
        public static string ConvertOneNumber(string numStr)
        {
            int num = Convert.ToInt32(numStr);
            return zeroToNine[num];
        }

        //หลักสิบ 2 หลัก 
        public static string ConvertTwoNumbers(string numStr)
        {
            int n = numStr.Length;

            for(int j = 0; j < n; j++)
            {
                int num = Convert.ToInt32(numStr[j]) - 48;

                if (num == 0)
                {
                    int numNext = Convert.ToInt32(numStr[j + 1]) - 48;
                    if (numNext == 0)
                    {
                        return "";
                    }
                    else
                    {
                        return zeroToNine[numNext];
                    }
                }

                if (num == 1)
                {
                    int numNext = Convert.ToInt32(numStr[j + 1]) - 48;
                    return tenToNineteen[numNext];
                }
                else
                {
                    if (numStr[j + 1] == '0')
                    {
                        return twentyToNinety[num - 2];
                    }
                    else
                    {
                        int numNext = Convert.ToInt32(numStr[j + 1]) - 48;
                        return twentyToNinety[num - 2] + " " + zeroToNine[numNext];
                    }
                }
            }

            return "";

        }

        //หลักร้อย 3 หลัก 
        public static string ConvertThreeNumbers(string numStr)
        {
            int n = numStr.Length;
            int num = Convert.ToInt32(numStr[0]) - 48;
            string twoNum = numStr.Substring(1,2);

            if (num == 0)
            {
                if (ConvertTwoNumbers(twoNum) == "")
                    return "";
                else
                    return ConvertTwoNumbers(twoNum);
            }
            else
            {
                if(ConvertTwoNumbers(twoNum) == "")
                    return zeroToNine[num] + " " + suffixNumber[0];
                else
                    return zeroToNine[num] + " " + suffixNumber[0] + " and " + ConvertTwoNumbers(twoNum);
            }

        }

        //หลักพัน 4 หลัก 
        public static string ConvertFourNumbers(string numStr)
        {
            int n = numStr.Length;
            int num = Convert.ToInt32(numStr[0]) - 48;
            string threeNum = numStr.Substring(1, 3);

            if (num == 0)
            {
                if (ConvertThreeNumbers(threeNum) == "")
                    return "";
                else
                    return ConvertThreeNumbers(threeNum);
            }
            else
            {
                if (ConvertThreeNumbers(threeNum) == "")
                    return zeroToNine[num] + " " + suffixNumber[1];
                else
                {
                    return zeroToNine[num] + " " + suffixNumber[1] + " and " + ConvertThreeNumbers(threeNum);
                }
            }
        }

        //หลักหมื่น 5 หลัก
        public static string ConvertFiveNumbers(string numStr)
        {
            int n = numStr.Length;
            string twoFirstNum = numStr.Substring(0,2);
            string threeLastNum = numStr.Substring(2,3);

            if(ConvertTwoNumbers(twoFirstNum) == "")
                 return ConvertTwoNumbers(twoFirstNum) + ConvertThreeNumbers(threeLastNum);
            else
                return ConvertTwoNumbers(twoFirstNum) + " " + suffixNumber[1] + " and " + ConvertThreeNumbers(threeLastNum);
        }

        //หลักแสน 6 หลัก
        public static string ConvertSixNumbers(string numStr)
        {
            int n = numStr.Length;
            string threeFirstNum = numStr.Substring(0, 3);
            string threeLastNum = numStr.Substring(3, 3);

            if (ConvertThreeNumbers(threeFirstNum) == "")
                return ConvertThreeNumbers(threeLastNum);
            else
            {
                if (ConvertThreeNumbers(threeLastNum) == "")
                    return ConvertThreeNumbers(threeFirstNum) + " " + suffixNumber[1];
                else
                    return ConvertThreeNumbers(threeFirstNum) + " " + suffixNumber[1] + " and " + ConvertThreeNumbers(threeLastNum);
            }
        }

        //หลักล้าน 7 หลัก
        public static string ConvertSevenNumbers(string numStr)
        {
            int n = numStr.Length;
            string firstNum = numStr[0].ToString();
            string threeMiddletNum = numStr.Substring(1, 3);
            string threeLastNum = numStr.Substring(4, 3);
            if (firstNum == "0")
            {
                if (ConvertThreeNumbers(threeMiddletNum) == "")
                    return ConvertThreeNumbers(threeLastNum);
                else
                    return ConvertThreeNumbers(threeMiddletNum) + " " + suffixNumber[1] + " and " + ConvertThreeNumbers(threeLastNum);
            }
            else
            {
                if(ConvertThreeNumbers(threeMiddletNum) == "")
                    return ConvertOneNumber(firstNum) + " " + suffixNumber[2] + " and " + ConvertThreeNumbers(threeLastNum);
                else
                   return ConvertOneNumber(firstNum) + " " + suffixNumber[2] + " and " + ConvertThreeNumbers(threeMiddletNum) + " " + suffixNumber[1] + " and " + ConvertThreeNumbers(threeLastNum);
            }
        }
    }
}
>>>>>>> .r6
